package com.wc.demo.controller;

import com.wc.demo.bo.UserInfoBo;
import com.wc.demo.service.UserService;
import com.wc.demo.vo.UserInfoVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author WangChen 2064318526@qq.com
 * @date 2023/8/10 16:09
 */
@RestController
@RequestMapping("/demo")
@Api(tags = "用户管理")
public class UserController {
    @Resource
    UserService userService;

    @ApiOperation("hello测试")
    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, Spring Boot!";
    }

    @ApiOperation("保存或更新用户")
    @PostMapping("/saveOrUpdate")
    public boolean saveOrUpdate(@RequestBody UserInfoBo userInfoBo) {
        return userService.saveOrUpdate(userInfoBo);
    }

    @ApiOperation("根据id删除用户")
    @GetMapping("/delById")
    public boolean delById(@ApiParam(value = "用户id",required = true)@RequestParam Long id) {
        return userService.delById(id);
    }

    @ApiOperation("获取所有用户")
    @GetMapping("/getAllUser")
    public List<UserInfoVo> getAllUser() {
        return userService.getAllUser();
    }

    @ApiOperation("根据id获取用户")
    @GetMapping("/getUserById")
    public UserInfoVo getUserById(@ApiParam(value = "用户id",required = true) @RequestParam Long id) {
        return userService.getUserById(id);
    }

    @ApiOperation("根据用户名获取用户")
    @GetMapping("/getUserByName")
    public UserInfoVo getUserByName(@ApiParam(value = "用户名",required = true)@RequestParam String name) {
        return userService.getUserByName(name);
    }

}